import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/phoenix/common/widget/dk_gap_widget.dart';
import 'package:dk_flutter_module_sale/phoenix/my_setting/resource/meSettingResource.dart';
import 'package:dk_flutter_module_sale/r.dart';
import '../bean/bean_my_info.dart';

class MyInfoWidget extends StatelessWidget {
  final UserInfoBean userInfoBean;
  final VoidCallback onTapHeader;
  final double infoHeight = 165;
  final double upHeight = 50;
  MyInfoWidget({this.userInfoBean,this.onTapHeader});
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      decoration: BoxDecoration(//去除分割线
          color: Color(0xFF3274F9),
        border: Border(
            top: BorderSide(color: Color(0xFF3274F9),width: 0),
          bottom:BorderSide(color: Color(0xFFF5F5F5),width: 0),

    ),
      ),
      height: infoHeight,
      child: Stack(
        children: <Widget>[
          Positioned(
            top: 0,
            child: Container(
              height: upHeight,
              //color: Color(0xFF3274F9),
              color: Colors.red,
            ),
          ),
          Positioned(
            top: upHeight,
            left: 0,
            right: 0,
            child:  Container(
              height: (infoHeight - upHeight),
              color: Colors.white,
            ),
          ),
          Positioned(
            top: infoHeight - 10,
            left: 0,
            right: 0,
            child:  Container(
              height: 10,
              color: Color(0xFFF5F5F5),
            ),
          ),
          Positioned(
            top: 0,
            left: 16,
            right: 16,
            child: buildCard(),
          )
        ],
      ),
    );
  }

  InkWell buildCard() {
    return InkWell(
        onTap:this.onTapHeader,
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
          boxShadow:<BoxShadow>[
            BoxShadow(
              color: Color(0x08000000),
              offset: Offset(0, 2),
              blurRadius: 5
            )
          ]
        ),
        child: Column(
          children: <Widget>[
            Container(
              child: Row(
                children: <Widget>[
                  ClipOval(
                      child:CachedNetworkImage(
                          imageUrl: this.userInfoBean.headerImageUrl,
                          width: 64,
                          height: 64,
                          fit: BoxFit.contain,
                          placeholder: (context, url) {
                            return Image.asset(R.imagesCommonDefaultHeadImagePng,
                                height: 64,
                                width: 64,
                                fit: BoxFit.contain);
                          })),
                  DKGaps.hGap16,
                  Expanded(
                    child: buildNamePositionColumn(),
                  ),
                ],
              ),
              padding: EdgeInsets.fromLTRB(10, 10, 10, 20),
            ),
            Container(
              padding: EdgeInsets.only(left: 20,right: 10,top: 0,bottom: 20),
              child: buildBottomDaysRow(),
            )
          ],
        ),
      ),
    );
  }

  Column buildNamePositionColumn() {
    return Column(
      crossAxisAlignment:CrossAxisAlignment.start ,
      children: <Widget>[
        Row(
          children: <Widget>[
            Text(
              userInfoBean.name,
              style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize:17,
                  fontWeight: FontWeight.w600
              ),
            ),
            Spacer(),
            Image.network(MESettingImage.rightImageURL,
              fit: BoxFit.contain,
              width: 12,
              height: 12,),
          ],
        ),
        DKGaps.vGap5,
        Row(
          children: <Widget>[
            Text(
              this.userInfoBean.department,
                style: TextStyle(
                  color: Color(0xFF666666),
                  fontSize:14,
                )
            ),
            DKGaps.hGap10,
            Text(
                this.userInfoBean.position,
                style: TextStyle(
                  color: Color(0xFF666666),
                  fontSize:14,
                )
            ),
          ],
        )
      ],
    );
  }

  Row buildBottomDaysRow() {
    return Row(
      children: <Widget>[
        Expanded(
          child: buildDayItem(MESettingImage.joinDaysURL,"加入蛋壳",this.userInfoBean.joinDays.toString() + "天"),
        ),
      ],
    );
  }

  Row buildDayItem(String imageURL, String headText,String trailText) {
    return Row(
      children: <Widget>[
        Image.network(
          imageURL,
          width:16,
          height: 16,
          fit: BoxFit.contain,
        ),
        DKGaps.hGap7,
        Text(
          headText,
          style: TextStyle(
            fontSize: 14,
            color: Color(0xFF999999)
          ),
        ),
        DKGaps.hGap3,
        Text(
          trailText,
          style: TextStyle(
              fontSize: 13,
              color: Color(0xFF999999)
          ),
        )
      ],
    );
  }
}

